<script>
layui.config({
	base:'#(ctx)/manage/_assets/libs/layui/extends/'
}).extend({
	treeSelect:'treeSelect'
}).use(['form', 'layedit', 'upload', 'element', 'treeSelect'], function(){
	var $ = layui.$, form = layui.form, layedit = layui.layedit, upload = layui.upload, treeSelect = layui.treeSelect;
	
	### 初始化下拉选择器
	treeSelect.render({
		elem: '#columnSelect',	### css选择器，推荐使用id
		data: '#(ctx)/manage/column/ajaxGetColumnTree', ### 请求地址
		type: 'post', ### ajax请求方式：post/get
		search: true,
		key: {
			id: 'id' ### 返回数据中主键的属性名称，默认值为id
		},
		click: function (data) { ### 节点点击回调函数
		},
		style: {
			folder: {
				enable: false
			},
			line: {
				enable: true
			}
		},
	### 加载完成后的回调函数
		success: function (d) {
			treeSelect.checkNode('columnSelect', #(column.parentId));
			treeSelect.refresh('columnSelect');
		}
	});

	###自定义验证规则
	form.verify({
		V_name : function(value, item) {
			if (value.length < 2 || value.length > 50) {
				return '名称必须2到50字符';
			}
		}
	});

	form.on('select(url-type)', function(data){
		switchLinkType(data.value);
	});

	form.on('select(page-type)', function(data){
		buildInnerUrl();
	});
	form.on('select(page-name)', function(data){
		buildInnerUrl();
	});

	#if(!column.url)
	switchLinkType("#(column.urlType??'inner')");
	#end

	var placeholder_inner = "默认以域名开头，因此不需要输入#site('site_domain')，以‘/’开头";
	var placeholder_outer = "必须以'http://’或‘https://’开头";
	function switchLinkType(type){
		if(type == "inner"){
			$("#ID_column_url").attr("placeholder", placeholder_inner);
			$(".page-info").show();
			buildInnerUrl();
		} else {
			$("#ID_column_url").attr("placeholder", placeholder_outer);
			$(".page-info").hide();
		}
	}
	
	function buildInnerUrl(){
		console.log($("#ID_page_type").val());
		console.log($("#ID_page_name").val());
		var pageType = $("#ID_page_type").val(), pageName = $("#ID_page_name").val();
		var url = "";
		if(pageType == "/") {###首页特殊处理
			url = url + "/";
		} else {
			url = url + $("#ID_page_type").val() + "/" + $("#ID_page_name").val() + ".html";
		}
		$("#ID_column_url").val(url);
	}
});
</script>